package com.mall.concurrency.example.singleton;

/**
 * @Author:zwy
 * @Despriction:
 * @Date:Create in 15:00 2018/5/29
 * @Modify By:
 */

/**
 * 枚举模式；最安全
 */
public class SingletonExamle7 {
    private SingletonExamle7(){

    }
    public static SingletonExamle7 getInstance(){
        return Singlenton.INSTANCE.getSingleton();
    }
    private enum Singlenton{
        INSTANCE;
        private SingletonExamle7 singleton;
        //JVM保证这个方法只调用一次
        Singlenton(){
            singleton = new SingletonExamle7();
        }

        public SingletonExamle7 getSingleton() {
            return singleton;
        }
    }

    public static void main(String[] args) {
        System.out.println(SingletonExamle7.getInstance().hashCode());
        System.out.println(SingletonExamle7.getInstance().hashCode());

    }
}
